package com.feizhoutuobang.shapeline.bo;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Paragraph {

	private int id = 0;
	private String title = "";
	private String link = "";
	private String publishTime = "";
	private File content = null;
	private Section section = null;
	private List<Resource> resources = new ArrayList<Resource>();
	private String storePath = "";
	private String storeName = "";
	private Paragraph previousParagraph = null;
	private Paragraph nextParagraph = null;
	
	public Paragraph(Section section) {
		this.section = section;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}

	public String getPublishTime() {
		return publishTime;
	}

	public void setPublishTime(String publishTime) {
		this.publishTime = publishTime;
	}

	public String getContent() {
		FileInputStream stream = null;
		InputStreamReader reader = null;
		BufferedReader br = null;
		try {
			StringBuilder s = new StringBuilder("");
			stream = new FileInputStream(content);
			reader = new InputStreamReader(stream, "utf-8");
			br = new BufferedReader(reader);
			String line = null; 
			while ((line = br.readLine()) != null) { 
				s.append(line).append("\r\n");
			}
			return s.toString();
		}
		catch (Exception e) {
			return "";
		}
		finally {
			try {br.close(); } catch (Exception e) {}
			try {reader.close(); } catch (Exception e) {}
			try {stream.close(); } catch (Exception e) {}
		}
	}

	public void setContent(File content) {
		this.content = content;
	}

	public Section getSection() {
		return section;
	}

	public void setSection(Section section) {
		this.section = section;
	}

	public List<Resource> getResources() {
		return resources;
	}

	public void setResources(List<Resource> resources) {
		this.resources = resources;
	}

	public String getStorePath() {
		return storePath;
	}

	public void setStorePath(String storePath) {
		this.storePath = storePath;
	}

	public String getStoreName() {
		return storeName;
	}

	public void setStoreName(String storeName) {
		this.storeName = storeName;
	}

	public Paragraph getPreviousParagraph() {
		return previousParagraph;
	}

	public void setPreviousParagraph(Paragraph previousParagraph) {
		this.previousParagraph = previousParagraph;
	}

	public Paragraph getNextParagraph() {
		return nextParagraph;
	}

	public void setNextParagraph(Paragraph nextParagraph) {
		this.nextParagraph = nextParagraph;
	}
}
